﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace YourLastOptionsDialog.Views
{
    /// <summary>
    /// The editor for string values.
    /// </summary>
    public partial class StringEditor : UserControl
    {
        /// <summary>
        /// The input scope property
        /// </summary>
        public static readonly DependencyProperty InputScopeProperty =
            DependencyProperty.Register(
                "InputScope", 
                typeof(InputScope), 
                typeof(StringEditor), 
                new PropertyMetadata(default(InputScope), InputScope_Changed));

        private static void InputScope_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var obj = d as StringEditor;
            if (obj != null)
            {
                var newValue = (InputScope)e.NewValue;
                obj.InputTextBox.InputScope = newValue;
            }
        }

        /// <summary>
        /// Gets or sets the input scope.
        /// </summary>
        public InputScope InputScope
        {
            get
            {
                return (InputScope)GetValue(InputScopeProperty);
            }

            set
            {
                SetValue(InputScopeProperty, value);
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="StringEditor"/> class.
        /// </summary>
        public StringEditor()
        {
            // Required to initialize variables
            InitializeComponent();
        }

        private void InputTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            InputTextBox.SelectAll();
        }
    }
}